#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <sys/wait.h>
int main()
{
    printf("main函数(%d)开始执行\n", getpid());
    // 创建子进程
    pid_t pid = fork();
    if (pid == 0)
    {
        // 子进程
        printf("子进程（%d)开始执行\n", getpid());
        //*argv[]是程序路径，NULL表示参数结束
        char *argv[] = {"/bin/ping","-c","10","www.baidu.com", NULL};
        //*envp[]是环境变量，NULL表示默认环境变量
        char *envp[] = {NULL};
        int ret = execve(argv[0], argv, envp);
        if (ret == -1)
        {
            perror("execve执行失败");
            exit(1);
        }
    }
    else if (pid > 0)
    {
        printf("父进程（%d)继续执行\n", getpid());
        waitpid(pid, NULL, 0);
    }
    printf("main函数(%d)结束执行\n", getpid());
    return 0;
}